package com.wl.network.demo04;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UDPClient {
    public static void main(String[] args) {
        try {
            //建立一个socket
            DatagramSocket datagramSocket = new DatagramSocket();
            //建一个包
            String msg = "你好";
            InetAddress localhost = InetAddress.getByName("localhost");
            //数据
            DatagramPacket datagramPacket = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length, localhost, 9090);
            //发送
            datagramSocket.send(datagramPacket);
            //关闭
            datagramSocket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
